# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Jeffrey Zhang <zhang.lei.fly@gmail.com>

pkgname=python-pytest-lsp
_name=${pkgname#python-}
pkgver=0.4.0
pkgrel=1
pkgdesc='Pytest plugin for end-to-end testing of language servers'
arch=('any')
url=https://swyddfa.github.io/lsp-devtools
license=('MIT')
depends=('python-packaging' 'python-pygls' 'python-pytest-asyncio')
makedepends=('git' 'python-build' 'python-hatchling' 'python-installer')
source=("git+https://github.com/swyddfa/lsp-devtools.git#tag=$_name-v$pkgver")
b2sums=('SKIP')

build() {
  cd lsp-devtools/lib/"$_name"
  python -m build --wheel --skip-dependency-check --no-isolation
  cd ../lsp-devtools
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd lsp-devtools/lib/"$_name"
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m installer ../lsp-devtools/dist/*.whl
  PATH="$PWD/test-env/bin:$PATH" test-env/bin/python -m pytest
}

package() {
  cd lsp-devtools/lib/"$_name"
  python -m installer --destdir="$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/"${_name/-/_}"-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
